/************************************************************
 * Copyright (C), 2022-2030, ripnano. Co., Ltd.
 * FileName:        form_progressbar.h
 * Author:          Dan Yin
 * Date:            2023-06-08
 * Description:     the class of progressbar
 * Version:         1.0.0.0
 **********************************************************/

#ifndef FORM_PROGRESSBAR_H
#define FORM_PROGRESSBAR_H

#include <QWidget>
#include <QTimer>

enum EM_PROCESS_STATE { E_PS_NONE, E_PS_IDLE, E_PS_RUNNING, E_PS_PROCESSING, E_PS_COMPLITED, E_PS_STOPPING };

namespace Ui {
class FormProgressbar;
}

class FormProgressbar : public QWidget
{
    Q_OBJECT

public:
    explicit FormProgressbar(QWidget *parent = 0);
    virtual ~FormProgressbar();

    void setValue(int nValue);
    int getValue(void);

signals:
    void signalRunTest(bool bStart, int nTimeConsuming, int nState);

    void signalProgressOver(bool bCancel);

private slots:
    void slotUpdateProgressBar();

    void on_pushButton_Test_clicked();

    void slotRunTest(bool bStart, int nTimeConsuming, int nState);

protected:
    void paintEvent(QPaintEvent *);

    // Triggers an event before it is switch language
    void changeEvent(QEvent *event);

private:
    void _start(int nCount = 0);
    void _stop(bool bCancel);

    // Draw progress with the digit format
    void _drawProgressBySecond(int nSec);

    // Convert seconds to time
    QString _seconds2Time(int nSeconds);

private:
    Ui::FormProgressbar *ui;

    QPixmap             m_pixBg;
    QPixmap             m_pixFg;
    QTimer              m_tmrRun;
    int                 m_nValue;
    int                 m_nSecondsCnt;
    bool                m_bStoped = true;
    QString             m_sPromptInfo = "";
    EM_PROCESS_STATE    m_eumProcessState = E_PS_NONE;

};

#endif // FORM_PROGRESSBAR_H
